﻿using System.Data;
using Loki.Data;
using Luna.Model.Common;

namespace Luna.Data.Common
{
    /// <summary>
    /// Mapper for data interface IGeolocalisationData.
    /// </summary>
    public partial class GeolocalisationDataMapper : LunaMapper<GeolocalisationData, IGeolocalisationData>
    {
        partial void Initialize();

        public GeolocalisationDataMapper()
        {
            GetAllRequest = DefaultGetAllRequest;
            GetRequest = DefaultGetRequest;
            InsertRequest = DefaultInsertRequest;
            UpdateRequest = DefaultUpdateRequest;
            DeleteRequest = DefaultDeleteRequest;

            Initialize();
        }

        private const string DefaultGetAllRequest = "Meta.geolocalisation_select_all";
        private const string DefaultGetRequest = "Meta.geolocalisation_select";
        private const string DefaultInsertRequest = "Meta.geolocalisation_insert";
        private const string DefaultUpdateRequest = "Meta.geolocalisation_update";
        private const string DefaultDeleteRequest = "Meta.geolocalisation_delete";

        private const string LatitudeColumnName = "Latitude";
        private const string LongitudeColumnName = "Longitude";
        private const string DisplayNameColumnNuame = "DisplayName";
        private const string ItemTypeColumnName = "ItemType";

        protected override void LoadCoreData(IGeolocalisationData entity, IDataRecord record)
        {
            entity.Latitude = record.GetDouble(LatitudeColumnName);
            entity.Longitude = record.GetDouble(LongitudeColumnName);
            entity.DisplayName = record.GetString(DisplayNameColumnNuame);
            entity.ItemType = record.GetEnum<SearchItemType>(ItemTypeColumnName);
        }

        protected override void MapSaveParameters(IDatabaseCommand command, IGeolocalisationData entity)
        {
            command.AddParameter(LatitudeColumnName, entity.Latitude);
            command.AddParameter(LongitudeColumnName, entity.Longitude);
            command.AddParameter(DisplayNameColumnNuame, entity.DisplayName);
            command.AddParameter(ItemTypeColumnName, entity.ItemType.ToString());
            command.AddParameter(IDParameterName, entity.PK);
        }
    }
}